From 4c4a5347a6fbe69a8f525db3cf9f6826c70944cf Mon Sep 17 00:00:00 2001
From: Derek Lesho <dlesho@codeweavers.com>
Date: Fri, 10 Jan 2020 15:34:45 -0600
Subject: [PATCH] Add some semi-stubs in user32.

---
diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c
index 10f17bb4c3..345f3946bc 100644
--- a/dlls/user32/sysparams.c
+++ b/dlls/user32/sysparams.c
@@ -4487,39 +4544,112 @@ BOOL WINAPI PhysicalToLogicalPoint( HWND hwnd, POINT *point )
 }
 
 /**********************************************************************
- *              GetDisplayConfigBufferSizes (USER32.@)
+ * GetDisplayConfigBufferSizes [USER32.@]
  */
 LONG WINAPI GetDisplayConfigBufferSizes(UINT32 flags, UINT32 *num_path_info, UINT32 *num_mode_info)
 {
-    FIXME("(0x%x %p %p): stub\n", flags, num_path_info, num_mode_info);
+    TRACE("0x%x %p %p\n", flags, num_path_info, num_mode_info);
 
     if (!num_path_info || !num_mode_info)
         return ERROR_INVALID_PARAMETER;
 
-    *num_path_info = 0;
-    *num_mode_info = 0;
-    return ERROR_NOT_SUPPORTED;
+    *num_path_info = 1;
+    *num_mode_info = 2;
+    return ERROR_SUCCESS;
 }
 
+#define D3DKMDT_VSS_NTSC_M          0x6
+
 /***********************************************************************
- *              QueryDisplayConfig (USER32.@)
- */
++ *              QueryDisplayConfig (USER32.@)
++ * TODO: support multiple monitors
++ */
 LONG WINAPI QueryDisplayConfig(UINT32 flags, UINT32 *numpathelements, DISPLAYCONFIG_PATH_INFO *pathinfo,
                                UINT32 *numinfoelements, DISPLAYCONFIG_MODE_INFO *modeinfo,
                                DISPLAYCONFIG_TOPOLOGY_ID *topologyid)
 {
-    FIXME("(%08x %p %p %p %p %p)\n", flags, numpathelements, pathinfo, numinfoelements, modeinfo, topologyid);
-
-    if (!numpathelements || !numinfoelements)
-        return ERROR_INVALID_PARAMETER;
-
-    if (!*numpathelements || !*numinfoelements)
-        return ERROR_INVALID_PARAMETER;
+    LUID adapter_id;
+    POINT origin;
+    HMONITOR monitor;
+    MONITORINFOEXW monitor_info;
+    DEVMODEW mode;
+    DISPLAYCONFIG_SOURCE_MODE *source_mode = &modeinfo[0].DUMMYUNIONNAME.sourceMode;
+    DISPLAYCONFIG_TARGET_MODE *target_mode = &modeinfo[1].DUMMYUNIONNAME.targetMode;
+    DISPLAYCONFIG_PATH_SOURCE_INFO *source_info = &pathinfo[0].sourceInfo;
+    DISPLAYCONFIG_PATH_TARGET_INFO *target_info = &pathinfo[0].targetInfo;
+
+    TRACE("(%08x %p %p %p %p %p)\n", flags, numpathelements, pathinfo, numinfoelements, modeinfo, topologyid);
+
+    if (*numpathelements < 1 || *numinfoelements < 2)
+        return ERROR_INSUFFICIENT_BUFFER;
+
+    origin.x = 0;
+    origin.y = 0;
+    monitor = MonitorFromPoint(origin, MONITOR_DEFAULTTOPRIMARY);
+    monitor_info.cbSize = sizeof(monitor_info);
+    if (!(GetMonitorInfoW(monitor, (MONITORINFO*) &monitor_info)))
+    {
+        return ERROR_GEN_FAILURE;
+    }
+    if (!(EnumDisplaySettingsW(monitor_info.szDevice, 0, &mode)))
+    {
+        return ERROR_GEN_FAILURE;
+    }
 
-    if (!flags)
-        return ERROR_INVALID_PARAMETER;
+    AllocateLocallyUniqueId(&adapter_id);
+
+    source_mode->width = mode.dmPelsWidth;
+    source_mode->height = mode.dmPelsHeight;
+    source_mode->pixelFormat = DISPLAYCONFIG_PIXELFORMAT_32BPP;
+    source_mode->position.x = 0;
+    source_mode->position.y = 0;
+
+    /* no idea what pixel rate is */
+    target_mode->targetVideoSignalInfo.pixelRate = 0xdeadbeef;
+    target_mode->targetVideoSignalInfo.hSyncFreq.Numerator = mode.dmDisplayFrequency * mode.dmPelsHeight;
+    target_mode->targetVideoSignalInfo.hSyncFreq.Denominator = 1;
+    target_mode->targetVideoSignalInfo.vSyncFreq.Numerator = mode.dmDisplayFrequency;
+    target_mode->targetVideoSignalInfo.vSyncFreq.Denominator = 1;
+    target_mode->targetVideoSignalInfo.activeSize.cx = mode.dmPelsWidth;
+    target_mode->targetVideoSignalInfo.activeSize.cy = mode.dmPelsHeight;
+    target_mode->targetVideoSignalInfo.totalSize.cx = mode.dmPelsWidth;
+    target_mode->targetVideoSignalInfo.totalSize.cy = mode.dmPelsHeight;
+    target_mode->targetVideoSignalInfo.DUMMYUNIONNAME.videoStandard = D3DKMDT_VSS_NTSC_M;
+    target_mode->targetVideoSignalInfo.scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED;
+
+    modeinfo[0].infoType = DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE;
+    modeinfo[0].id = 0;
+    modeinfo[0].adapterId = adapter_id;
+    modeinfo[1].infoType = DISPLAYCONFIG_MODE_INFO_TYPE_TARGET;
+    modeinfo[1].id = 0;
+    modeinfo[1].adapterId = adapter_id;
+
+    source_info->adapterId = adapter_id;
+    source_info->id = 0;
+    source_info->DUMMYUNIONNAME.modeInfoIdx = 0;
+    source_info->statusFlags = DISPLAYCONFIG_SOURCE_IN_USE;
+
+    target_info->adapterId = adapter_id;
+    target_info->id = 0;
+
+    target_info->DUMMYUNIONNAME.modeInfoIdx = 1;
+    target_info->outputTechnology = DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI;
+    target_info->rotation = DISPLAYCONFIG_ROTATION_IDENTITY;
+    target_info->scaling = DISPLAYCONFIG_SCALING_IDENTITY;
+    target_info->refreshRate.Numerator = mode.dmDisplayFrequency;
+    target_info->refreshRate.Denominator = 1;
+    target_info->scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED;
+    target_info->targetAvailable = TRUE;
+    target_info->statusFlags = DISPLAYCONFIG_TARGET_IN_USE;
+
+    pathinfo[0].flags = DISPLAYCONFIG_PATH_ACTIVE;
+
+    if (flags == QDC_DATABASE_CURRENT && topologyid)
+    {
+        *topologyid = DISPLAYCONFIG_TOPOLOGY_INTERNAL;
+    }
 
-    return ERROR_NOT_SUPPORTED;
+    return ERROR_SUCCESS;
 }
 
 /***********************************************************************
@@ -4527,7 +4657,7 @@ LONG WINAPI QueryDisplayConfig(UINT32 flags, UINT32 *numpathelements, DISPLAYCON
  */
 LONG WINAPI DisplayConfigGetDeviceInfo(DISPLAYCONFIG_DEVICE_INFO_HEADER *packet)
 {
-    FIXME("stub: %p\n", packet);
+    static const WCHAR testW[] = {'t','e','s','t',0};
 
     if (!packet || packet->size < sizeof(*packet))
         return ERROR_GEN_FAILURE;
@@ -4538,34 +4668,34 @@ LONG WINAPI DisplayConfigGetDeviceInfo(DISPLAYCONFIG_DEVICE_INFO_HEADER *packet)
     {
         DISPLAYCONFIG_SOURCE_DEVICE_NAME *source_name = (DISPLAYCONFIG_SOURCE_DEVICE_NAME *)packet;
         if (packet->size < sizeof(*source_name))
-            return ERROR_INVALID_PARAMETER;
+        {
+            return ERROR_INSUFFICIENT_BUFFER;
+        }
+
+        memcpy(source_name->viewGdiDeviceName, testW, sizeof(testW));
 
-        return ERROR_NOT_SUPPORTED;
+        return ERROR_SUCCESS;
     }
     case DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME:
     {
         DISPLAYCONFIG_TARGET_DEVICE_NAME *target_name = (DISPLAYCONFIG_TARGET_DEVICE_NAME *)packet;
         if (packet->size < sizeof(*target_name))
-            return ERROR_INVALID_PARAMETER;
+        {
+            TRACE("%u, %lu\n", packet->size, sizeof(*target_name));
+            return ERROR_INSUFFICIENT_BUFFER;
+        }
 
-        return ERROR_NOT_SUPPORTED;
-    }
-    case DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE:
-    {
-        DISPLAYCONFIG_TARGET_PREFERRED_MODE *preferred_mode = (DISPLAYCONFIG_TARGET_PREFERRED_MODE *)packet;
-        if (packet->size < sizeof(*preferred_mode))
-            return ERROR_INVALID_PARAMETER;
+        target_name->flags.DUMMYUNIONNAME.value = 0;
+        target_name->outputTechnology = DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI;
+        target_name->connectorInstance = 0;
 
-        return ERROR_NOT_SUPPORTED;
-    }
-    case DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME:
-    {
-        DISPLAYCONFIG_ADAPTER_NAME *adapter_name = (DISPLAYCONFIG_ADAPTER_NAME *)packet;
-        if (packet->size < sizeof(*adapter_name))
-            return ERROR_INVALID_PARAMETER;
+        memcpy(target_name->monitorFriendlyDeviceName, testW, sizeof(testW));
+        memcpy(target_name->monitorDevicePath, testW, sizeof(testW));
 
-        return ERROR_NOT_SUPPORTED;
+        return ERROR_SUCCESS;
     }
+    case DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE:
+    case DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME:
     case DISPLAYCONFIG_DEVICE_INFO_SET_TARGET_PERSISTENCE:
     case DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_BASE_TYPE:
     case DISPLAYCONFIG_DEVICE_INFO_GET_SUPPORT_VIRTUAL_RESOLUTION:
@@ -4574,7 +4704,6 @@ LONG WINAPI DisplayConfigGetDeviceInfo(DISPLAYCONFIG_DEVICE_INFO_HEADER *packet)
     case DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE:
     case DISPLAYCONFIG_DEVICE_INFO_GET_SDR_WHITE_LEVEL:
     default:
-        FIXME("Unimplemented packet type: %u\n", packet->type);
-        return ERROR_INVALID_PARAMETER;
+            return ERROR_NOT_SUPPORTED;
     }
 }
-- 
2.24.1
